// src/request/wgqApi.ts
import request from './service'

// 定义基础API地址
const BASE_URL = 'http://localhost:21001'; // 使用公共API地址
// const BASE_URL = 'http://www.bingo1440.top:21001'; // 使用公共API地址

/**
 * 登录接口
 * @param {string} account 用户账号
 * @param {string} password 密码
 * @returns {Promise} 返回登录结果
 */
export const login = async (account: string, password: string) => {
  try {
    console.log('发送登录请求:', { account, password }); // 添加日志
    const response = await request.post('/users/login', {
      account,
      password
    });
    console.log('登录API响应数据:', response);
    return response;
  } catch (error) {
    console.error('登录请求失败:', error);
    throw new Error('登录请求失败');
  }
};

/**
 * 分级医生-多条件搜索医生综合列表
 * @param {object} params 查询参数
 * @returns {Promise} 返回医生列表数据
 */
export const searchDoctors = async (params: any) => {
  const { page = 1, size = 100, name = '', department = '' } = params;
  const queryParams = { page, size, name, department };
  
  try {
    console.log('发送搜索医生请求:', queryParams); // 添加日志
    const response = await request.get('/doctor/search_doctor', queryParams);
    console.log('搜索医生API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取医生列表失败:', error);
    throw new Error('获取医生列表失败');
  }
};

/**
 * 分级护士-多条件搜索护士综合列表
 * @param {object} params 查询参数
 * @returns {Promise} 返回护士列表数据
 */
export const searchNurses = async (params: any) => {
  const { page = 1, size = 100, name = '', department = '' } = params;
  const queryParams = { page, size, name, department };
  
  try {
    console.log('发送搜索护士请求:', queryParams); // 添加日志
    const response = await request.get('/doctor/search_nurse', queryParams); // 假设护士搜索接口为 /doctor/search_nurse
    console.log('搜索护士API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取护士列表失败:', error);
    throw new Error('获取护士列表失败');
  }
};

/**
 * 查询所有科室名称
 * @returns {Promise} 返回科室名称列表
 */
export const getDepartmentNames = async () => {
  try {
    console.log('发送获取科室名称请求');
    const response = await request.get('/department/departnames');
    console.log('获取科室名称API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取科室名称失败:', error);
    throw new Error('获取科室名称失败');
  }
};

/**
 * 查询所有医生名称
 * @returns {Promise} 返回医生名称列表
 */
export const getDoctorNames = async () => {
  try {
    console.log('发送获取医生名称请求');
    const response = await request.get('/doctor/doctornames');
    console.log('获取医生名称API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取医生名称失败:', error);
    throw new Error('获取医生名称失败');
  }
};

/**
 * 查询所有护士名称
 * @returns {Promise} 返回护士名称列表
 */
export const getNurseNames = async () => {
  try {
    console.log('发送获取护士名称请求');
    const response = await request.get('/doctor/nursenames');
    console.log('获取护士名称API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取护士名称失败:', error);
    throw new Error('获取护士名称失败');
  }
};

/**
 * 分级医生-修改医生信息
 * @param {object} params 修改的信息
 * @returns {Promise} 返回修改结果
 */
export const editDoctor = async (params: any) => {
  try {
    console.log('发送修改医生请求:', params) // 添加日志
    const response = await request.post('/doctor/edit_doctor', params)
    console.log('修改医生API响应数据:', response)
    return response
  } catch (error) {
    console.error('修改医生请求失败:', error)
    throw new Error('修改医生请求失败')
  }
}

/**
 * 分级护士-修改护士信息
 * @param {object} params 修改的信息
 * @returns {Promise} 返回修改结果
 */
export const editNurse = async (params: any) => {
  try {
    console.log('发送修改护士请求:', params) // 添加日志
    const response = await request.post('/doctor/edit_nurse', params) // 假设护士编辑接口为 /doctor/edit_nurse
    console.log('修改护士API响应数据:', response)
    return response
  } catch (error) {
    console.error('修改护士请求失败:', error)
    throw new Error('修改护士请求失败')
  }
}

/**
 * 获取医生/护士当日排班
 * @param {number} id 医生或护士ID
 * @returns {Promise} 返回排班数据
 */
export const getDnDayline = async (id: number) => {
  try {
    console.log('发送获取排班请求:', { id });
    const response = await request.get('/doctor/get_dn_dayline', { id });
    console.log('获取排班API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取排班请求失败:', error);
    throw new Error('获取排班请求失败');
  }
};

/**
 * 修改医生/护士当日排班
 * @param {object} params 修改的排班信息
 * @returns {Promise} 返回修改结果
 */
export const editDnDayline = async (params: any) => {
  try {
    console.log('发送修改排班请求:', params);
    const response = await request.post('/doctor/edit_dn_dayline', params);
    console.log('修改排班API响应数据:', response);
    return response;
  } catch (error) {
    console.error('修改排班请求失败:', error);
    throw new Error('修改排班请求失败');
  }
};


/**
 * 获取疾病大数据
 * @returns {Promise} 返回疾病大数据
 */
export const getDiseaseData = async () => {
  try {
    console.log('发送获取疾病大数据请求');
    const response = await request.get('/infomationcenter/disease');
    console.log('获取疾病大数据API响应数据:', response);
    return response;
  } catch (error) {
    console.error('获取疾病大数据失败:', error);
    throw new Error('获取疾病大数据失败');
  }
};




